package com.yuebao.config;

import com.alibaba.ttl.threadpool.TtlExecutors;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy;
import java.util.concurrent.TimeUnit;

//线程池
@Configuration
public class TaskConfig {
    
    /**
     * 消费消息用线程池
     * @return
     */
    @Bean(name = "messageConsumeExecutor")
    public ExecutorService messageConsumeExecutor() {
        ExecutorService ttlExecutorService = TtlExecutors
                .getTtlExecutorService(new ThreadPoolExecutor(4, 200, 300, TimeUnit.SECONDS, new LinkedBlockingQueue<>(10), new CallerRunsPolicy()));
        return ttlExecutorService;
    }
}
